<template>
<!-- 任务管理模块-核保分单任务管理-强制END页面 -->
    <div class="fillcontain">
        <!-- 查询条件 -->
        <div class="fastQuery">
            <el-row>
           <el-col :span="2" class="fastQuery_title"><i class="el-icon-tickets"></i><span> 查询条件</span></el-col>
           <el-col :span="10">
           </el-col>
                <el-col :span="4" class="moreCondition">
                    <span v-if="!isShow" @click="showorhide">更多条件 <i class="el-icon-d-arrow-right"></i></span>
                    <span v-if="isShow" @click="showorhide">收起 <i class="el-icon-d-arrow-left"></i></span>
                </el-col>
                <el-col :span="8"></el-col>
            </el-row>
        </div>
        <el-form v-show="isShow" :model="searchParams"   label-width="100px" class="search_container">
            <el-row>
                <el-col :span="6" class="common-box">
					<el-form-item label="分公司" prop="orgId">
						<el-select v-model="searchParams.orgId" placeholder="分公司" clearable>
							<el-option v-for="item in companylist" :key="item.SBUSIORGID" :label="item.SORGNAME" :value="item.SBUSIORGID"></el-option>
						</el-select>
					</el-form-item>
                </el-col>
                <el-col :span="6" class="common-box">
					<el-form-item label="险种类型" prop="risk">
						<el-select v-model="searchParams.risk" placeholder="险种类型" clearable>
							<el-option v-for="item in insmains" :key="item.value" :label="item.name" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
                </el-col>
                <el-col :span="6" class="common-box">
					<el-form-item label="组号" prop="groupno">
						<el-input v-model="searchParams.groupno" placeholder="组号" clearable></el-input>
					</el-form-item>
                </el-col>
                <el-col :span="6" class="common-box">
					<el-form-item label="受理号" prop="caseno">
						<el-input v-model="searchParams.caseno" placeholder="受理号" clearable></el-input>
					</el-form-item>
                </el-col>
                <el-col :span="6" class="common-box">
					<el-form-item label="保单号" prop="chdrnum">
						<el-input v-model="searchParams.chdrnum" placeholder="保单号"  oninput="if(value.length>8) value=value.slice(0,8)"  clearable></el-input>
					</el-form-item>
                </el-col>
                <el-col :span="6" class="common-box" >
					<el-form-item label="检出人" prop="checkoutId">
						<el-input v-model="searchParams.checkoutId" placeholder="检出人" clearable></el-input>
					</el-form-item>
                </el-col>
				<el-col :span="6" class="common-box">
					<el-form-item label="电子投保标识号" prop="appFrom">
						<el-select v-model="searchParams.appFrom" placeholder="电子投保标识号" clearable>
							<el-option v-for="item in appFroms" :key="item.value" :label="item.label" :value="item.value">
							</el-option>
						</el-select>
					</el-form-item>
				</el-col>
                <el-col :span="6" class="common-box">
					<el-form-item label="任务状态" prop="routeid">
						<el-select v-model="searchParams.routeid" placeholder="任务状态" clearable>
							<el-option v-for="item in routeids" :key="item.routeid" :label="item.content" :value="item.routeid">
							</el-option>
						</el-select>
					</el-form-item>
                </el-col>
                <el-col :span="6" class="text_right" style="float: right;">
                    <el-button type="primary" icon="el-icon-search" @click="search"></el-button>
                    <el-button type="primary" plain  icon="el-icon-refresh" @click="resetSearch"></el-button>
                </el-col>
            </el-row>
        </el-form>
        <div class="contain">
             <!-- 操作按钮 -->
            <el-row class="pb10"> 
                <el-col :span="24">
                    <el-button type="danger" plain @click="end">End单</el-button>
                </el-col>
            </el-row>
            <!-- 查询结果 -->
          <div class="table_container">
			<el-table ref="multipleDataTable" v-loading="loading" :data="tableData" highlight-current-row
				header-cell-class-name="table-header-class"  style="width:100%">
				<el-table-column type="selection" > </el-table-column>
				<el-table-column min-width="120" property="checkoutid" label="检出人" align='center' show-overflow-tooltip>
				</el-table-column>
				<el-table-column min-width="100" property="risk" label="保单类型" align='center' show-overflow-tooltip>
				</el-table-column>
				<el-table-column min-width="100" property="orgname" label="机构" align='center' sortable show-overflow-tooltip>
				</el-table-column>
				<el-table-column min-width="80" property="channel" label="渠道" align='center' sortable show-overflow-tooltip>
				</el-table-column>
				<el-table-column min-width="100" property="chdrnum" label="保单号" align='center' sortable show-overflow-tooltip>
				</el-table-column>
				<el-table-column min-width="90" property="caseno" label="受理号" align='center' sortable show-overflow-tooltip>
				</el-table-column>
				<el-table-column min-width="100" property="spolicyer" label="投保人" align='center' sortable show-overflow-tooltip>
				</el-table-column>
				<el-table-column min-width="100" property="insured" label="被保险人" align='center' sortable show-overflow-tooltip>
				</el-table-column>
				<el-table-column min-width="120" property="crtableName" label="主合同名称" align='center' sortable show-overflow-tooltip>
				</el-table-column>
				<el-table-column min-width="100" property="tasklevel" :formatter="changeLevel" label="任务级别" align='center'
					sortable show-overflow-tooltip>
				</el-table-column>
				<el-table-column min-width="160" property="sapptime" label="受理日期" align='center' show-overflow-tooltip>
				</el-table-column>
				
				<el-table-column property="scantime" min-width="160" label="最近处理时间" align='center' show-overflow-tooltip>
				</el-table-column>
				
				<el-table-column min-width="120" property="taskno" :formatter="changeUpdateTime" label="任务上传时间" align='center'
					show-overflow-tooltip>
				</el-table-column>
				<el-table-column min-width="120" property="issamecustom" label="多保单标记" align='center' show-overflow-tooltip>
				<template slot-scope="scope">
				    <el-link type="primary" @click="showMorePolicy(scope.row.policyholderno)" v-if="scope.row.issamecustom == '0'">{{scope.row.policyholderno}}
				    </el-link>
					<span type="primary"  v-if="scope.row.issamecustom != '0'">{{scope.row.policyholderno}}
					</span>
				</template>
				</el-table-column>
				<el-table-column min-width="80" property="groupno" label="组号" align='center' show-overflow-tooltip>
				</el-table-column>
				<el-table-column min-width="120" property="historyhandler" label="历史处理人" align='center' show-overflow-tooltip>
				</el-table-column>
				<el-table-column min-width="100" label="流转信息" align='center' show-overflow-tooltip>
					<template slot-scope="scope">
						<el-link class="point" type="primary" @click="showTaskChange(scope.row.taskno)">流转信息
						</el-link>
					</template>
				</el-table-column>
				<el-table-column min-width="50" label="备注" align='center' show-overflow-tooltip>
					<template slot-scope="scope">
						<el-link class="point" type="primary" @click="showRemark(scope.row.taskno)">备注
						</el-link>
					</template>
				</el-table-column>
				<el-table-column min-width="100" label="影像信息" align='center' show-overflow-tooltip>
					<template slot-scope="scope">
						<el-link class="point" type="primary" @click="showImage(scope.row)">影像信息
						</el-link>
					</template>
				</el-table-column>
				
				<el-table-column property="routeid" v-if="false"></el-table-column>
				<el-table-column property="insuredbrithday" v-if="false"></el-table-column>
				<el-table-column property="flagZT" v-if="false"></el-table-column>
				<el-table-column property="policyholderno" v-if="false"></el-table-column>
				<el-table-column property="policyholdername" v-if="false"></el-table-column>
				<el-table-column property="insuredno" v-if="false"></el-table-column>
				<el-table-column property="chdrnum" v-if="false"></el-table-column>
				<el-table-column property="tasklevel" v-if="false"></el-table-column>
				<el-table-column property="ischeckout" v-if="false"></el-table-column>
			</el-table>
				<el-row>
				<el-col :span="24">
					<div class="pagination">
						<el-pagination background v-if='paginations.total > 0' :page-sizes="paginations.pageSizes" :page-size="paginations.pageSize"
							:layout="paginations.layout" :total="paginations.total" :current-page='paginations.pageIndex' @current-change='handleCurrentChange'
							@size-change='handleSizeChange'>
						</el-pagination>
					</div>
				</el-col>
				</el-row>
          </div>
        </div>
	
		<!-- 备注 -->
		<remark-list  :business="'NB'" :taskNo="remarkTaskNo" :drawer="showRemarkFlag" @close="hideRemark"></remark-list>
		<!-- 任务流向记录 -->
		<task-change-list  :business="'NB'"  :taskNo="taskChangeTaskNo" :drawer="showTaskChangeFlag" @close="hideTaskChange"></task-change-list>
		<!--影像列表-->
		<cdfs-image-list :drawer="showImageFlag" :applnum="showImageApplnum" @close="hideImage"></cdfs-image-list>
		<!-- 同被保人多保单-->
		<more-policy-list  :business="'NB'"  :policyholderno="morePolicyPolicyholderno" :drawer="showMorePolicyFlag" @close="hideMorePolicy"></more-policy-list>
		
    </div>
</template>

<script>
    import constant from '@/utils/constant';
	import {
		isCntainChinese,
		isNotNumber
	} from '@/api/refund/RefundCommon';
	import RemarkList from "../taskCenter/remarkList";
	import cdfsImageList from "@/page/common/cdfsImageList";
	import taskChangeList from '../taskCenter/taskChangeList';
	import MorePolicyList from "../taskCenter/morePolicyList";
	import {getSsyOrgMap} from '@/api/taskCenter/taskCommon';
	import taskConstants, {getSelectList} from '@/utils/taskConstants';
	import {
		getCompanylist,
		queryNodes
	} from "@/api/taskManager/distributeTask";
	import TaskConstants ,{call} from "@/api/taskManager/common"
    export default {
		components:{
			RemarkList,
			taskChangeList,
			cdfsImageList,
			MorePolicyList
		},
        data(){
            return {
				emptySearchParams: {}, //空的查询
                newTaskCirculaDialog:false, //默认隐藏流转记录弹框
                isShow:false,
				insmains:TaskConstants.insmain,
				routeids:[],
				companylist:[],
				ssyMap:{},
				taskChangetableData:[],
				tableData:[],
				remarkTaskNo: "",
				showRemarkFlag: false,
				taskChangeTaskNo :"",
				showTaskChangeFlag : false,
				showImageFlag: false,
				showImageApplnum: '',
				morePolicyPolicyholderno: "",
				showMorePolicyFlag: false,
				appFroms:[],
                // 查询条件
                searchParams:{
                    orgId:'', 
                    risk:'', 
                    groupno: '',
                    caseno: '',
                    chdrnum: '',
                    checkoutId: '',
                    routeid: '',
					appFrom:'',
					pageNumber:'',
					pageSize:''
                },
                loading:false,
              //需要给分页组件传的信息
                paginations: {
                    total: 0,        // 总数
                    pageIndex: 1,  // 当前位于哪页
                    pageSize: 10,   // 1页显示多少条
                    pageSizes: [5, 10, 15, 20],  //每页显示多少条
                    layout: "total, sizes, prev, pager, next, jumper"   // 翻页属性
                },
            }
        },
		mounted() {
			queryNodes().then( data =>this.routeids=data);
			getSsyOrgMap().then(data => this.ssyMap = data);
			this.appFroms = getSelectList(taskConstants.appFrom);
		},
        created(){
			this.emptySearchParams = JSON.parse(JSON.stringify(this.searchParams));
			getCompanylist().then(data =>this.companylist=data);
        },
		activated(){
		    document.onkeydown = (event)=>{
		        var e = event || window.event || arguments.callee.caller.arguments[0];
		        if (e && e.keyCode == 113) {
		            this.search();
		        }
		    };
		}, 
        methods: {
			showMorePolicy(morePolicyPolicyholderno) {
			    this.morePolicyPolicyholderno = morePolicyPolicyholderno;
			    this.showMorePolicyFlag = true;
			},
			hideMorePolicy() {
			    this.morePolicyPolicyholderno = '';
			    this.showMorePolicyFlag = false;
			},
			showImage(row) {
				this.showImageApplnum = row.caseno;
				this.showImageFlag = true;
			},
			hideImage() {
				this.showImageApplnum = "";
				this.showImageFlag = false;
			},
			show() {
				this.$store.dispatch('loading/CHANGE_LOADING', true);
			},
			cancle() {
				this.$store.dispatch('loading/CHANGE_LOADING', false)
			},
			showRemark(taskNo) {
				this.remarkTaskNo = taskNo;
				this.showRemarkFlag = true;
			},
			hideRemark() {
				this.remarkTaskNo = "";
				this.showRemarkFlag = false;
			},
			showTaskChange(taskNo) {
				this.taskChangeTaskNo = taskNo;
				this.showTaskChangeFlag = true;
			},
			hideTaskChange() {
				this.taskChangeTaskNo = "";
				this.showTaskChangeFlag = false;
			},
			changeLevel(row) {
				if (row.tasklevel == "") {
					return "0";
				}
				return row.tasklevel;
			},
			getOrgName(value) {
				for (var key in this.ssyMap){
					if (this.ssyMap[key]["sbusiorgid"] && this.ssyMap[key]["sbusiorgid"] == value){
						value = this.ssyMap[key]["sorgname"]
						break;
					}
				}
				return value;
			},
			changeUpdateTime(row) {
				if (row.taskno != '') {
					let sTaskTime = row.taskno.substring(0, 14);
					let sTime = sTaskTime.substring(0, 4) + "-" + sTaskTime.substring(4, 6) + "-" + sTaskTime.substring(6, 8);
					sTime = sTime + " " + sTaskTime.substring(8, 10) + ":" + sTaskTime.substring(10, 12) + ":" + sTaskTime.substring(
						12, 14);
					return sTime;
				}
				return "";
			},
			resetSearch() {
				this.searchParams = JSON.parse(JSON.stringify(this.emptySearchParams));
			},
			/* end单 */
			end() {
				let arrTaskList = [];
				this.$refs.multipleDataTable.selection.forEach(item => {
					arrTaskList.push(item);
				});
				if (arrTaskList.length == 0) {
					this.$message.error("请选择需要END单的任务！");
					return;
				}
				let tasknos =[];
				let strCaseNo = "";
				for (var key in arrTaskList) {
					let item = arrTaskList[key];
					strCaseNo=strCaseNo+item["caseno"]+",";
					tasknos.push(item["taskno"]);
				}
				if(confirm("确认受理号："+strCaseNo+"流转到《end单》？")){
					this.show();
					call(TaskConstants.apis['forceEnd'],tasknos,"post").then( result => {
						this.$message.success(result.resultMsg);
						this.cancle();
						this.paginations.pageIndex = 1;
						this.paginations.pageSize = 10;
						this.getList();
					}).catch(error => {
						console.log(error);
						this.cancle();
					});
				}
			},
			search() {
				
				if(this.searchParams.chdrnum !="" ){
					if ( isNotNumber(this.searchParams.chdrnum) || this.searchParams.chdrnum.length !=8) {
						this.$message.error("请正确输入保单号！");
						return;
					}
				}
				if(this.searchParams.caseno !="" &&  isNotNumber(this.searchParams.caseno)){
					this.$message.error("请正确输入受理号！");
					return;

				}
				if (this.searchParams.groupno != "" && isCntainChinese(this.searchParams.groupno)) {
					this.$message.error("请正确输入组号！");
					return;
				}
				if (this.searchParams.checkoutId != "" && isCntainChinese(this.searchParams.checkoutId)) {
					this.$message.error("请正确输入检出人！");
					return;
				}
				this.paginations.pageIndex = 1;
				this.paginations.pageSize = 10;
				this.getList();
			},
            showorhide() {
                this.isShow = !this.isShow;
            },
            // 查询列表
            getList(){
                this.paginations.total=0;
				this.tableData = [];
				this.searchParams.pageNumber = this.paginations.pageIndex;
				this.searchParams.pageSize = this.paginations.pageSize;
                this.$store.dispatch('loading/CHANGE_LOADING',true)
                call(TaskConstants.apis['queryEndTaskList'],this.searchParams,"post").then(result => {
                    this.$store.dispatch('loading/CHANGE_LOADING',false)
                    if (result.resultCode == constant.SUCCESS && result.data && result.data.list.length) {
						let pageData = result.data;
						this.paginations.total = pageData.total;
						this.paginations.currentPage = pageData.pageNum;
						this.tableData = pageData.list;
						this.tableData.forEach(item => {
							item["orgname"] = this.getOrgName(item.orgname);
						})
					} 
					// else {
					// 		this.$message.error("无符合条件任务！");
					// 	}
						
                }).catch(err =>{
                    this.$store.dispatch('loading/CHANGE_LOADING',false);
                })
            },
            // 每页多少条切换
            handleSizeChange(pageSize) {
               this.paginations.pageSize = pageSize;
               this.getList();
            },
            // 上下分页
            handleCurrentChange(page) {
               this.paginations.pageIndex = page;
               this.getList();
            },
        }
    }
</script>

<style lang="less" scoped>
 .fillcontain {
	padding-bottom: 0;
 
	.fastQuery {
		padding: 15px 20px 10px 20px;
		background: #fff;
		border-bottom: 1px solid #e1e1e1;
 
		.fastQuery_title {
			color: #666;
			padding: 6px 0px;
		}
 
		.fastQuery_item {
			margin: 0 10px;
		}
 
		.item_default {
			.el-button {
				color: #409EFF !important;
				border-color: #c6e2ff !important;
				background-color: #ecf5ff !important;
			}
 
		}
	
		.moreCondition {
			color: #68a3fc;
			cursor: pointer;
			padding: 6px 0px;
	
			.el-icon-d-arrow-right {
				transform: rotate(90deg);
			}
	
			.el-icon-d-arrow-left {
				transform: rotate(-90deg);
			}
		}
	}
 }
 
 .contain {
	background: #fff;
	padding: 10px;
	margin-bottom: 20px;
 }
 
 .pagination {
	padding: 10px 20px;
	text-align: right;
 }
 
 .operationIcon {
	// padding: 12px;
	border: 1px solid #e5e5e5;
	border-radius: 50%;
	width: 22px;
	height: 22px;
	display: inline-block;
	cursor: pointer;
	box-shadow: 0 0 3px #f9f9f9;
 }
 
 .search_container {
	padding: 20px 20px 0 20px;
	//    border-top: 1px solid #e1e1e1;
 }
 
 .common-box {
	padding-bottom: 15px;
 }
 
 .common-lab {
	line-height: normal !important;
	text-align: right;
 
	.labelName {
		text-align: right;
	}
 }
</style>
<style>
	.el-table .red {
		color: red
	}

	.el-table .green {
		color: green
	}

	.el-table .blue {
		color: blue
	}

	.el-table .orange {
		color: orange
	}

	.el-table .default {
		color: white
	}
</style>


